package com.zzh.partnersys.controller;

import com.zzh.partnersys.common.exception.ResultUtils;
import com.zzh.partnersys.oss.service.OSSService;
import com.zzh.partnersys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.http.HttpServletRequest;

/**
 * @author �?�?�?
 * @version 1.0
 */
@RestController
@RequestMapping("/oss")
public class OSSController {
    @Autowired
    private OSSService ossService;

    @Autowired
    private UserService userService;

    /**
     * 上传url的同时修改用户信�?
     * @return
     */
    @PostMapping("/uploadFile")
    public ResultUtils uploadFileUpdateUser(@RequestBody MultipartFile file, HttpServletRequest request){
        String url = ossService.fileUpload(file);
        //异步修改数据库的用户信息url
        userService.updateUserAvatarUrl(url,request);
        return ResultUtils.ok(url);
    }

}
